package com.tzpay.tzpay.api;

import com.tzpay.tzpay.bean.UserInfo;
import com.tzpay.tzpay.utils.CryptTool;
import com.tzpay.tzpay.utils.Utils;

/**
 * Created by chenfeiyue on 16/3/15.
 */
public class OrderRefundRequest {
    public String merchantId = UserInfo.getInstance().getMerchantNo();
    public String subMerchantId = UserInfo.getInstance().getSubMerchantNo();
    public String merchantPwd = UserInfo.getInstance().getMerchantPwd();  // 商户执行时需填入相应密码
    public String oldOrderNo; // 原扣款成功的订单号
    public String oldOrderReqNo;
    public String refundReqNo = Utils.getTime();; // 该流水在商户处必须是唯一的，而且每次发起退款时，都必须是唯一的
    public String refundReqDate = Utils.getDateTime();
    public String transAmt;
    public String channel = UserInfo.getInstance().getChannel();
    public String ledgerDetail = UserInfo.getInstance().getLedgerDetail();
    public String bgUrl = UserInfo.getInstance().getBackUrl();
    public String mac;

    public String calculateMac() {
        StringBuilder sb = new StringBuilder();//组装mac加密明文串
        sb.append("MERCHANTID=").append(merchantId);
        sb.append("&MERCHANTPWD=").append(merchantPwd);
        sb.append("&OLDORDERNO=").append(oldOrderNo);
        sb.append("&OLDORDERREQNO=").append(oldOrderReqNo);
        sb.append("&REFUNDREQNO=").append(refundReqNo);
        sb.append("&REFUNDREQDATE=").append(refundReqDate);
        sb.append("&TRANSAMT=").append(transAmt);
        sb.append("&LEDGERDETAIL=").append(ledgerDetail);
        sb.append("&KEY=").append(UserInfo.getInstance().getMerchantDataKey());//此处是商户的key

        String enMac = "";
        try {
            System.err.println(sb.toString());
            enMac = CryptTool.md5Digest(sb.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return enMac;
    }

    public String getMerchantId() {
        return merchantId;
    }

    public void setMerchantId(String merchantId) {
        this.merchantId = merchantId;
    }

    public String getSubMerchantId() {
        return subMerchantId;
    }

    public void setSubMerchantId(String subMerchantId) {
        this.subMerchantId = subMerchantId;
    }

    public String getMerchantPwd() {
        return merchantPwd;
    }

    public void setMerchantPwd(String merchantPwd) {
        this.merchantPwd = merchantPwd;
    }

    public String getOldOrderNo() {
        return oldOrderNo;
    }

    public void setOldOrderNo(String oldOrderNo) {
        this.oldOrderNo = oldOrderNo;
    }

    public String getOldOrderReqNo() {
        return oldOrderReqNo;
    }

    public void setOldOrderReqNo(String oldOrderReqNo) {
        this.oldOrderReqNo = oldOrderReqNo;
    }

    public String getRefundReqNo() {
        return refundReqNo;
    }

    public void setRefundReqNo(String refundReqNo) {
        this.refundReqNo = refundReqNo;
    }

    public String getRefundReqDate() {
        return refundReqDate;
    }

    public void setRefundReqDate(String refundReqDate) {
        this.refundReqDate = refundReqDate;
    }

    public String getTransAmt() {
        return transAmt;
    }

    public void setTransAmt(String transAmt) {
        this.transAmt = transAmt;
    }

    public String getChannel() {
        return channel;
    }

    public void setChannel(String channel) {
        this.channel = channel;
    }

    public String getLedgerDetail() {
        return ledgerDetail;
    }

    public void setLedgerDetail(String ledgerDetail) {
        this.ledgerDetail = ledgerDetail;
    }

    public String getBgUrl() {
        return bgUrl;
    }

    public void setBgUrl(String bgUrl) {
        this.bgUrl = bgUrl;
    }

    public String getMac() {
        return mac;
    }

    public void setMac(String mac) {
        this.mac = mac;
    }
}
